// app.js
App({
  async onLaunch () {
    let that = this
    //云开发初始化
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力');
    } else {
      wx.cloud.init({
        env: "cytfadmini-1gali3r244372a1f",
        traceUser: true,
      })
    }
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 通过共享环境，调用前端云函数getuserid获取openid
    var c1 = new wx.cloud.Cloud({
      resourceAppid: 'wxbfd52ca8da22670f', // 资源方APPID
      resourceEnv: 'cloud1-4gcsxcql7d341258', // 资源方环境 ID
    })
    // 保存共享环境为全局变量
    that.globalData.c1 = c1 
    // 跨账号调用，必须等待 init 完成
    // init 过程中，资源方小程序对应环境下的 cloudbase_auth 函数会被调用，并需返回协议字段（见下）来确认允许访问、并可自定义安全规则
    await c1.init()
    // 获取openID
    await c1.callFunction({
      name: "getuserid",
      success(res) {
        that.globalData.myid = res.result.event.userInfo.openId
        // 将openid存入myid（key)
        wx.setStorageSync('myid', res.result.event.userInfo.openId)
        console.log('app.js myid', that.globalData.myid)
      }
    })

    //获取屏幕高度
    wx.getSystemInfo({
      success: function (res) {
        let clientHeight = res.windowHeight
        let clientWidth = res.windowWidth
        let rpxR = 750 / clientWidth
        var calc = (clientHeight * rpxR).toFixed() - 100
        var calc1 = (clientHeight * rpxR).toFixed() //- 150
        that.globalData.windowHeight = String(calc) + "rpx"
        that.globalData.windowHeight1 = String(calc1) + "rpx"
        // console.log("屏幕高度为",that.globalData.windowHeight)
      }
    })
  },
  globalData: {
    userInfo: null,
    block:'',
    name:'',
    mobile:'',
    station:'',
    myid: '',
    windowHeight: '', //-100rpx
    windowHeight1: '', //-150rpx
    c1:{} //保存共享环境为全局变量
  }
})
